package cn.auto.service;

import java.util.HashMap;
import java.util.List;

import cn.auto.common.model.Cases;
import cn.auto.common.model.Module;
import cn.auto.utility.Status;

public class ModuleService {
	
	Module module= new Module();
	List<Module> infos=null;
	
	public HashMap<Object, Object> getModules(String pid) {
		infos=module.searchModule(pid);
		return Status.searchResultCode(infos);
	}
	
	public String addModule(HashMap<String, String> addInfo) {
		boolean isAdd=false;
		String pid = addInfo.get("pid");
		String name = addInfo.get("mname");
		
		isAdd = module.addModule(pid, name);
		return Status.booleanResultCode(isAdd);
	}
	
	public String removeModule(String pid,String mid) {
		Cases cases=new Cases();
		Boolean isDel=false;
		List<Cases> case_info=cases.searchCases(pid, mid);
		//if any case in the module , then not allow delete this module
		if (case_info.size()==0){
			isDel=module.delModule(mid);
		}
		return Status.booleanResultCode(isDel);
		
	}

}
